/* Andreas Baum
 * Server.java
 * Starts up the central login server and handles new connections 
 * Starts a thread for each new user
 * CS 78 - Networks
 */

package server;

import java.io.IOException;
import java.net.ServerSocket;

public class Server {

	public static int PORT = 4445;
	public static ServerSocket serverSocket;


	public static void main(String[] args) throws IOException {
		
		// Print welcome message:
		System.out.println("Welcome Andreas Baum's iTunes Library-Sharing Proxy");
		System.out.println("Starting up...");
		
		// Bind to port:
		try {
			serverSocket = new ServerSocket(PORT);
		} catch (IOException e) {
			System.out.println("ERROR: Could not listen on port: " + PORT);
			System.exit(-1);
		}
		// Output information:
		System.out.println("Listening on port " + PORT + ".");
		
		while (true) {
			// listen for a new connection:
			try {
				// create a client thread to handle the client:
				new ServerThread(serverSocket.accept());
			} catch (IOException e) {
				System.out.println("Accept failed: " + PORT);
				System.exit(-1);
			}
		}
	}

}